<?php


// no direct access
defined('_JEXEC') or die('Restricted access');

class HelpDeskViewUsers extends HelpDeskView 
{
	/**
	 * (non-PHPdoc)
	 * @see v1_00/com_helpdesk/site/HelpDeskView#display($tpl)
	 */
	function display($tpl = null) 
	{
		$user = &HelpDeskConfig::getUser();
		$database = HelpDeskConfig::getDBO();
		$model = &$this->getModel();
		$app = HelpDeskConfig::getApplication();

		// check config		
			$config = &HelpDeskConfig::getInstance();
			$this->assignRef( 'config', $config );

		// If user is not a manager or superadmin, redirect
			$isManager = HelpDeskHelperManager::isUser( $user->id );
			if (!$isManager) 
			{
				$link = 'index2.php?option='._THISCOMPONENT;
				$link = HelpDeskRoute::_( $link, false );
				$msg = HelpDeskText::_( 'You are not authorized to manage tickets' );
				$app->redirect( $link, $msg, 'notice' );
				return;
			}
			 
		// get the data
			$items = $model->getData();
			$this->assignRef('items', $items);

		// filterlists
			$javascript = 'onchange="document.adminForm.submit();"';
			$filterLists = array();
			$this->assignRef('filterLists', $filterLists );
			
		// set search
			$searchterm = $model->getField( $config->getFieldname( 'search' ) );
			$search = "<input type='text' name='".$config->getFieldname( 'search' )."' value='$searchterm' class='text_area' onchange='submitForm(\"".HelpDeskRequest::getVar( 'task' )."\")' />";
			$this->assignRef( 'search' , $search );
			
		// pagenavigation
			$this->assignRef( 'order' , $model->getOrder() );
			$this->assignRef( 'order_dir' , $model->getOrderDir() );
			$pagination = $model->getPagination();    
			$this->assignRef( 'pagination' , $pagination);
		
		// form
			$formAction = "index2.php";
			$this->assignRef( 'formAction' , $formAction );
			$validate = josSpoofValue();
			$formValidate = "<input type='hidden' name='{$validate}' value='1' />"; 
			$this->assignRef( 'formValidate' , $formValidate );
			$this->assignRef( 'formOption' , HelpDeskRequest::getVar( 'option' ) );
			$this->assignRef( 'formController' , $this->_name );
		
		parent::display($tpl);
    }	 
}